﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Chapter21.View
{
    using System.Data;
    /// <summary>
    /// NvaigateCollection.xaml 的交互逻辑
    /// </summary>
    public partial class NavigateCollectionWindow : Window
    {
        private DataTable products;
        private BindingListCollectionView view;

        public NavigateCollectionWindow()
        {
            InitializeComponent();
            products = App.StoreDBDataSet.GetProducts();
            DataContext = products.DefaultView;
            view = (BindingListCollectionView)CollectionViewSource.GetDefaultView(DataContext);
            view.CurrentChanged += view_CurrentChanged; 
        }

        private void view_CurrentChanged(object sender, EventArgs e)
        {
            itemTextBlock.Text = "当前项 " + (view.CurrentPosition + 1).ToString() + " 共" + view.Count.ToString();
            prevButton.IsEnabled = view.CurrentPosition > 0;
            nextButton.IsEnabled = view.CurrentPosition < view.Count - 1;
        }

        private void prevButton_Click(object sender, RoutedEventArgs e)
        {
            view.MoveCurrentToPrevious();
        }

        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            view.MoveCurrentToNext();
        }
    }
}
